package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.HEmployeeInfoDto;
import com.crm.jdy.common.dto.WOutInfoDto;
import com.crm.jdy.common.pojo.HEmployeeInfo;
import com.crm.jdy.common.pojo.WOutInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.HEmployeeInfoService;
import com.crm.jdy.service.drp.WOutInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 员工表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "hEmployeeInfo", description = "员工表信息")
@RestController
@RequestMapping("/hEmployeeInfo")
public class HEmployeeInfoController{

    @Reference(version = "${service.version}", check = false)
    HEmployeeInfoService hEmployeeInfoService;

    @RateLimit()
    @ApiOperation("员工表信息")
    @PostMapping("/seleteHEmployeeInfo")
    public ResultVo seleteHEmployeeInfo(@RequestBody HEmployeeInfoDto wOutInfo){
        PageInfo<HEmployeeInfo> list = hEmployeeInfoService.seleteHEmployeeInfo(wOutInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新员工表信息")
    @PostMapping("/updateHEmployeeInfo")
    public ResultVo updateHEmployeeInfo(@ApiParam(value = "wOutInfo", required = true)
                                   @Validated @RequestBody HEmployeeInfo wOutInfo){
        boolean index = hEmployeeInfoService.updateHEmployeeInfo(wOutInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加员工表信息")
    @PostMapping("/addHEmployeeInfo")
    public ResultVo addHEmployeeInfo(@ApiParam(name = "wOutInfo", required = false)
                                @Validated @RequestBody HEmployeeInfo wOutInfo){
        boolean list  = hEmployeeInfoService.addHEmployeeInfo(wOutInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除员工表信息")
    @DeleteMapping("deleteHEmployeeInfo/{empId}")
    public ResultVo deleteHEmployeeInfo(@NotNull @ApiParam(name = "empId", value = "empId", required = true) @PathVariable String empId){
        boolean b = hEmployeeInfoService.removeHEmployeeInfo(empId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}